package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo12 {
    public static void main(String[] args) {

        try ( Connection conn = DBUtil.getConnection()){
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
            conn.setAutoCommit(false);
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入需要删除的用户名：");
            String username = sc.next();
            String sql = "DELETE FROM userinfo WHERE username=?";
            PreparedStatement statement = conn.prepareStatement(sql);
            statement.setString(1,username);
            int count = statement.executeUpdate();
            System.out.println(count>0?"删除成功！":"删除失败！");
            conn.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
